/**
 * Created by renzhiqiang on 17/7/24.
 */
import { Router, Route,IndexRoute, hashHistory } from 'react-router'
import React ,{Component, PropTypes, PureComponent} from "react";
import ReactDom from 'react-dom';
import ES5 from './ES5/index';
import ES6 from './ES6/index';
import Func from './fun/index';
import redux from './redux/index';
import createLogger from 'redux-logger';

import reactRedux from './reactRedux/index';
import sage from './sage/index';

import Header from './Header';
import { syncHistoryWithStore } from 'react-router-redux'
import { Provider} from 'react-redux'
import { createStore,applyMiddleware ,compose} from 'redux'
import store111 from './midwalle'
//
import { composeWithDevTools } from 'redux-devtools-extension';
// Reducer
function counter(state = { count: 0 }, action) {
    const count = state.count;
    switch (action.type) {
        case 'increase':
            return { count: count + 1 }
        default:
            return state
    }
}
// const enhancer = compose(
//     DevTools.instrument()
// );
// Store

const store = createStore(counter,applyMiddleware(createLogger));
// const store = createStore(counter, window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__());

const onError = ()=>{
    console.info('1111');
};

function routes() {
    return (
    <Route path="/" components={Header}>
        <Route path="/ES5" onEnter={onError}
               getComponent={(nextState, cb) => {
                    require.ensure([], (require) => {
                    cb(null, ES5)
               })}}
         />
        <Route path="/ES6" onEnter={onError}
               getComponent={(nextState, cb) => {
                   require.ensure([], (require) => {
                       cb(null, ES6)
                   })}}
        />
        <Route path="/func" onEnter={onError}
               getComponent={(nextState, cb) => {
                   require.ensure([], (require) => {
                       cb(null, Func)
                   })}}
        />
        <Route path="/redux"
               getComponent={ (nextState, cb) => {
                   require.ensure([], (require) => {
                       cb(null, redux)
                   })}}
        />
        <Route path="/reactRedux"
               getComponent={ (nextState, cb) => {
                   require.ensure([], (require) => {
                       cb(null, reactRedux)
                   })}}
        />
        <Route path="/sage"
               getComponent={ (nextState, cb) => {
                   require.ensure([], (require) => {
                       cb(null, sage)
                   })}}
        />
    </Route>
    )
}
// var route = [
//        {
//         path:"/",
//         getComponent(nextState, cb) {
//             require.ensure([], require => {
//                 cb(null,Header)
//             })
//         },
//         childRoutes:[
//             {
//                 path:"/repos/:name",
//                 onEnter:aa,
//                 getIndexRoute:(nextState, cb) => {
//                     require.ensure([], (require) => {
//                         cb(null, {component:ES6})
//                     })
//                 },
//                 childRoutes:[
//                     {
//                         path:"/aa",
//                         onEnter:aa,
//                         getComponent:(nextState, cb) => {
//                             require.ensure([], (require) => {
//                                 cb(null, ES6)
//                             })
//                         },
//                     }
//                 ]
//             }
//         ]
//     }
//    ];

// ReactDom.render(<Router routes={routes()} history={hashHistory} onError={onError}/>, document.getElementById('content'));
ReactDom.render(<Provider store={store}><Router routes={routes()} history={hashHistory} onError={onError}/></Provider>, document.getElementById('content'));
